﻿<?php
//error_reporting(0);
include("function.php");
include("timeline.class.php");
//include("mail/sendmail.php");
//判断登陆
judgeLogin();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="js/jquery-1.6.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--<meta http-equiv="X-UA-Compatible" content="IE=7" /><!--如果是IE8时强制以IE7显示-->
<meta name="keywords" content="食品笔记,食品,食品安全,饮食,饮食安全,生活"><!--SEO关键字-->
<meta name="description" content="食品笔记，你的饮食安全卫士"><!--SEO描述-->
<link rel="shortcut icon" type="image/ico" href="images/favicon.ico"><!--选项卡图标-->
<title>食品笔记 - 让生活更健康</title>
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/style.css">
<!--[if ie]>
<link rel="stylesheet" href="css/ie.css">
<script type="text/javascript" src="js/DD_belatedPNG.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('.png');/*在需要png透明的元素里面加上.png样式即可（class="png"）*/
</script>
<![endif]-->
</head>
<body>
	<div class="header w"><!-- header -->
		<div class="index-header w960 bc pr">
			<a href="home.php" class="score_logo score_img dib png fl mt10"></a>
			<div class="header_right fr">
				<ul class="header_nav fl tc fb f12 h mt5">
					<li><a href="home.php">首 页</a></li>
					<li><a href="report.php">饮食报告</a></li>
					<li><a href="newsmap.php" class="header_nav_hover">食品新闻</a></li>
					<li><a href="food.php">选食专栏</a></li>
					<li><a href="timeline.php">时光轴</a></li>
					<li><a href="share.php">分享</a></li>
				</ul>
				<a href="massage.php" class="header_myMessage tc fr ml5" title="私信"><?php echo showCountMassage($_SESSION['login_mail']);?></a><!-- 私信 -->
				
				<div class="header_myInfo fr f14 h pr">
					<a href="#" class="header_setup"><img src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" alt="" class="fl" /></a><!-- user_avatar -->
					<a href="#" class="fl header_setup"><?php echo showUserName();?></a><!-- user_nickname -->
					<div class="header_myInfoArrow score_img fl"></div>
					<ul class="header_hideInfo none pa tc w"><!-- hide_info -->
						<li><a href="#" class="header_setup">个人设置</a></li>
						<li><a href="modifymail.php">修改邮箱</a></li>
						<li><a href="password.php">修改密码</a></li>
						<li><a href="login_out.php">退出登录</a></li>
					</ul>
				</div>
				
			</div>
		</div>
	</div><!-- end_header -->
	<div class="pr">
		<div class="pa map_look_more tc oh"><div class="map_see_news png pa db"><a href="news.php" class="see_more_a f12">查看所有新闻</a></div></div>
		<div id="map_canvas" style="width: 100%; height: 590px"></div>
	</div>
	
	<div class="footer w maps_footer"><!-- footer -->
		<div class="w960 bc pr">
			<div class="pt10 welcome-footer map-welcome-footer bc">
				<span class="iphone-app-img dib png fl"></span><a href="#" class="iphone-app f12 a3 fl">iphone应用</a><a href="foodnote.apk" class="android-app f12 a3 fr">android应用</a><span class="android-app-img dib png fr"></span>
			</div>
			<div class="welcome-about mb10">
				<p class="f12 tc"><a href="#" class="a3">关于我们</a><span class="ml10 mr10">|</span><a href="#" class="a3">使用条款</a><span class="ml10 mr10">|</span><a href="#" class="a3">常见问题</a></p>
			</div>
			<div class="welcome-about f12 tc">
				<p class="a3 f12 c91">Copyright &copy; 2011-2012 Foodnote&nbsp;&nbsp;&nbsp;&nbsp; 湘ICP备09004495号-5</p>
			</div>
		</div>
	</div><!-- end_footer -->
	
	<?php
		//判断是否新用户登录
		$login_mail = $_SESSION['login_mail'];
		$login_status = judgeNewUser($login_mail);
		
		//获取用户数据
		$userData = getUserBasicInfo($_SESSION['login_mail']);
		
		if($login_status == 0)
		{
			echo "<div class='novice_login png pa w'>";
		}else
		{
			echo "<div class='novice_login png pa w none'>";
		}
	?>
		<div class="personal_info bc oh pb50 pr">
			<div class="personal_close score_img pa"></div>
			<h2 class="personal_title ml50 mt20 mb20">个人信息录入</h2>
			
			<form action="home.php" method="post" class="ml50">
				<fieldset class="fl">
					<p class="mt10"><label for="" class="personal_label f22">性别</label></p>
					<p class="mt10"><small class="personal_small f14">请选择：男/女</small></p>
					<p class="mt10">
						<select class="score_text score_select pl5 pr5 " name="sex">
					<?php  
						if($userData['user_sex']=="男"):
						
							echo "<option value='男' selected >男</option>";
							echo "<option value='女'>女</option>";
						
						elseif($userData['user_sex']=="女"):
						
							echo "<option value='男'>男</option>";
							echo "<option value='女' selected>女</option>";
						
						else:
						
							echo "<option value='' selected>--</option>";
							echo "<option value='男'>男</option>";
							echo "<option value='女'>女</option>";
						endif;
					?>
								
						</select>
					</p>
					<p class="mt10"><label for="" class="personal_label f22">年龄</label></p>
					<p class="mt10"><small class="personal_small f14">不同的年龄对饮食的需求不同，例如:23</small></p>
					<p class="mt10"><input type="text" class="score_text zy_ageVal pl5 pr5" name="age" value="<?php echo $userData['user_age'];?>"/></p>
					<p class="mt10"><label for="" class="personal_label f22">现居地</label></p>
					<p class="mt10"><small class="personal_small f14">请输入您现居地的省份名，例如:湖南</small></p>

					<p class="mt10">
						<select class="score_text score_select pl5 pr5 " name="city">
							<option value='<?php echo $userData['user_city'];?>' selected><?php echo $userData['user_city'];?></option>
							<option value='安徽'>安徽</option>
							<option value='福建'>福建</option>
							<option value='港澳台藏'>港澳台藏</option>
							<option value='甘肃'>甘肃</option>
							<option value='广东'>广东</option>
							<option value='广西'>广西</option>
							<option value='贵州'>贵州</option>
							<option value='海南'>海南</option>
							<option value='河北'>河北</option>
							<option value='黑龙江'>黑龙江</option>
							<option value='河南'>河南</option>
							<option value='湖北'>湖北</option>
							<option value='湖南'>湖南</option>
							<option value='江苏'>江苏</option>
							<option value='江西'>江西</option>
							<option value='吉林'>吉林</option>
							<option value='辽宁'>辽宁</option>
							<option value='内蒙古'>内蒙古</option>
							<option value='宁夏'>宁夏</option>
							<option value='青海'>青海</option>
							<option value='山东'>山东</option>
							<option value='山西'>山西</option>
							<option value='陕西'>陕西</option>
							<option value='四川'>四川</option>
							<option value='云南'>云南</option>
							<option value='新疆'>新疆</option>
							<option value='浙江'>浙江</option>
							<option value='直辖市'>直辖市</option>
						</select>
					</p>

					<p class="mt10"><label for="" class="personal_label f22">体重</label></p>
					<p class="mt10"><small class="personal_small f14">不同的体重对饮食的需求不同，单位：kg</small></p>
					<p class="mt10"><input type="text" class="score_text zy_weightVal pl5 pr5" name="weight" value="<?php echo $userData['weight'];?>"/> kg</p>
					<input type="hidden" value="<?php echo basename($_SERVER['PHP_SELF']);?>" name="fileName" />
					<input type="hidden" value="true" name="submited" />
					<input type="submit" value="确认提交" name="submit" class="personal_submit pa f18" />
				</fieldset>
			</form>
			<form method="post" action ="upload.php" enctype="multipart/form-data" target="hidden_frame" class="none">
				<fieldset>
					<input type="file" name="photo" id="photo" onchange="cli('p_submit');"/>
					<input type="submit" name="p_submit" value="保存" id="p_submit">
					<iframe name='hidden_frame' id="hidden_frame" style="border:none;" onreadystatechange="reflesh('<?php echo $_SESSION[login_mail]?>');"></iframe>
				</fieldset>
			</form>
			<form action="home.php" method="post" class="ml50">
				<fieldset>
					<a href="javascript:void(0)" onclick="cli('photo');"><img id="img" src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" class="personal_avatar pa" />
					<span class="pa click_upload">+点击上传头像</span>
					</a>
					<a href="javascript:void(0)" class="pa avatar_refresh" onclick="reflesh('<?php echo $_SESSION[login_mail]?>');">刷新</a>
				</fieldset>
			</form>
		</div>
	</div>
	
	<?php //qq_state 
	$qq_status = qq_status($login_mail); 
	if(isset($_SESSION['qq_nickname']) && $qq_status == 0):
	?>
	<div class="qq_tips_bg png pa w"><!-- QQ登陆提醒 -->
		<div class="qq_tips bc oh pb50 pr">
			<div class="qq_close score_img pa"></div>
			<h2 class="personal_title ml50 mt20 mb20">温馨提示</h2>
			<div class="qq_tipsh oh ml50 f14">
				<img src="images/tips_smile.png" alt="" class="fr png mr150" /><!-- 提示图片 -->
				<p>亲爱的</span class="a69"><?php echo $_SESSION['qq_nickname']; ?></span></p>
				<input type="hidden" class="qq_user_mail" value="<?php echo $login_mail;?>">
				<p>欢迎来到<span class="a69">食品笔记</span></p>
				<p>你的登陆账号为:<?php echo $_SESSION['login_mail'];?></p>
				<p>密码为:<?php echo $_SESSION['user_prepassword'];?></p>
				<p>为了方便下次登录，请即时<a href="password.php">修改密码</a>。</p>
			</div>
		</div>
	</div>
	<?php endif;?>
	
	<div id="scroeLoading" class="none png">
		<div class="loadingCenter bc pr">
			<div class="scoreLoading_bar bc pr"><div class="scoreLoading_cover pa"></div></div>
			<p class="loadingTips mt20 bc tc"></p>
		</div>
	</div>
	
	<!-- JavaScript -->
    <script type="text/javascript" src="http://ditu.google.cn/maps/api/js?sensor=false&language=zh-CN"></script>
    <script type="text/javascript" src="citydata.json"></script>
 <script type="text/javascript" src="jquery-1.6.min.js"></script>
    <script>
      var map = null;
	function color()
	{
		var provincesColor;
		$.ajax({
			url:'ajax/provinceColor.php',
			type:'get',
			data:{'flag':'true'},
			async:false,
			success:function(data){
				provincesColor = data;
			},
			dataType:'json'
		});

	return provincesColor;
	}//end color
	
	var provinces = color();

      var polyOptions = {
        strokeColor: "#9B868B",
        fillColor: "#FF8C69",
        fillOpacity: 0.6,
        strokeWeight: 1,
        zIndex: 1
      };

        function initialize() {
         var myOptions = {
         //   center: new google.maps.LatLng(32.694866, 105.996094),
            zoom: 6,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            streetViewControl: false
          };
          map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


 

	var initialLocation;
	var siberia = new google.maps.LatLng(60, 105);
	var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
	var browserSupportFlag =  new Boolean();
  if(navigator.geolocation) {
    browserSupportFlag = true;
    navigator.geolocation.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);     
 map.setCenter(initialLocation);

	var ajax;
	var ajaxViewMore;
	var temp = null;
/*
        var  marker = new google.maps.Marker({
           map:map,
           draggable:true,
           animation: google.maps.Animation.DROP,
           position: initialLocation,
	   title: '你所在的位置'
         }); 
        google.maps.event.addListener(marker, 'click', toggleBounce);
       // google.maps.event.addDomListener(marker, 'load', toggleBounce);
       
       function toggleBounce() {
        if (marker.getAnimation() != null) {
           marker.setAnimation(null);
         } else {
           marker.setAnimation(google.maps.Animation.BOUNCE);
	 } }//end fuction

*/		
loadMoreNews();

google.maps.event.addListener(map,"dragend",loadMoreNews);

function loadMoreNews(){

	var center = map.getCenter();
	var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var lngSpan = ( northEast.lng() - southWest.lng() ) / 2 ;
	var latSpan = ( northEast.lat() - southWest.lat() ) / 2;
	var lngE = center.lng() + lngSpan;
	var lngW = center.lng() - lngSpan;
	var latN = center.lat() + latSpan;
	var latS = center.lat() - latSpan;
	
	if(ajax){ ajax.abort(); } 
	ajax = $.post(
	'ajax/mapNews.php',
	{'lngE':lngE,'lngW':lngW,'latN':latN,'latS':latS},
	function(data)
	{
		showNewsOnMaps(data);
	},
	'json'
	);

//	showNewsOnMaps(result);
}//endfuction

function showNewsOnMaps(data)
{
	var title = new Array();
	var link = new Array();
	var news_time = new Array();
	var i;
	var address = new Array();

	if(data != null){
	$.each(data,function(key,valueNews){
//alert(key);
	var geocoder = new google.maps.Geocoder();
	    geocoder.geocode({address:key},function geoResults(results, status){
      if (status == google.maps.GeocoderStatus.OK) {
        var  pro_location_per =  results[0].geometry.location;

	var marker_per =  new google.maps.Marker({
      	       	position: pro_location_per, 
     		 map: map, 
     		 title: key
		 });  
	
	google.maps.event.addListener(marker_per,'click',function(){

	if(ajaxViewMore) { ajaxViewMore.abort();};
	ajaxViewMore = $.post(
	'ajax/viewNews.php',
	{'name':key},
	function(result){

	var contentString = '<div><span style="font-size:18px;colorL:black">'+key+'省的食品新闻</span>';

	$.each(result,function(moreKey,moreValue){

	contentString  = contentString + 
			'<a href='+moreValue.news_link+' style="text-decoration:none;font-size;12px;color:black" target="_blank"><br>' + moreValue.news_title + '</a><br /><span style="color:black;font-size:12px">'+ moreValue.news_time+'</span></p>';
	});

	contentString = contentString + '<a href=news.php?search='+key+'>查看'+key+'省的全部新闻</a></div>';

	var infowindow = new google.maps.InfoWindow({
	    content: contentString
	});//end inforwindow

	infowindow.open(map,marker_per);
	},//end result function
	'json'
	);//end post
	});//end lister	
     	
	 }else{
	       // alert("：error " + status);
		}
    	});//end analy

	//销毁变量
	pro_location_per = null;
	delete pro_location_per;

	marker_per = null;
	delete marker_per;

	});//end each
	}//endif
	
}//end fuction showOnMaps



    }, function() {
      handleNoGeolocation(browserSupportFlag);
    });
  // Try Google Gears Geolocation
  }

 function handleNoGeolocation(errorFlag) {
    if (errorFlag == true) {
      alert("Geolocation service failed.");
      initialLocation = newyork;
    } else {
      alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
      initialLocation = siberia;
    }
    map.setCenter(initialLocation);
  }
//check user IP end
/*         
          for (var i = 0, n = cityData.provinces.length; i < n; i++) {
            showBoundaryEx(cityData.provinces[i].b, getColor(cityData.provinces[i].n));
            //city
            // for (var j = 0, m = cityData.provinces[i].cities.length; j < m; j++) {
            //     showBoundary(cityData.provinces[i].cities[j].b);
            // }
          }
          for (var i = 0, n = cityData.municipalities.length; i < n; i++) {
            showBoundaryEx(cityData.municipalities[i].b, getColor(cityData.municipalities[i].n));
          }
          for (var i = 0, n = cityData.other.length; i < n; i++) {
            showBoundaryEx(cityData.other[i].b, getColor(cityData.other[i].n));
          }*/
        }//end init

        function isFloatNumber(value) {
          return (!isNaN(value));
        }

        function getColor(name) {
          for (var m = provinces.length - 1; m >= 0; m--) {
            if (provinces[m].indexOf(name) > -1) {
              var arr = provinces[m].split("-");
              return arr[1];
            }
          }
        }

        function showBoundaryEx(latLngs, color) {
          var paths = [],
            latLng = "",
            list = latLngs.split(";");
          for (i = list.length - 1; i >= 0; i--) {
            latLng = list[i].split(",");
            var lat = latLng[1],
              lng = latLng[0];
            if ((isFloatNumber(lat)) && (isFloatNumber(lng))) {
              paths.push(new google.maps.LatLng(lat, lng));
            }
          }

          var polygon = new google.maps.Polygon();
          polygon.setOptions(polyOptions);
          polygon.setOptions({
            fillColor: color
          });
          polygon.setPaths(paths);
          polygon.setMap(map);

        }

      google.maps.event.addDomListener(window, "load", initialize);
    </script>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>
	<?php if(!empty($_SESSION['qq_nickname'])){ ?>
<script type="text/javascript">  
	$(document).ready(function(){
		$('.qq_tips').show();
		
		$('.qq_close').click(function(event){
			$('.qq_tips_bg').hide();
		});
	})
</script>
	<?php } ?> 
<script type="text/javascript">  
 
 function cli(id){  
		var sub = document.getElementById(id);
   sub.click();  
//   if (/msie/i.test(navigator.userAgent)) //IE  
//   {  
//      sub.fireEvent("onclick");  
//   } else {  
//      var e = document.createEvent('MouseEvent');  
//      e.initEvent('click', false, false);  
//      sub.dispatchEvent(e);  
//   }
}

function reflesh(user){
	image_src="image.php?user_mail="+user+"&math="+Math.random(1);
	//alert(image_src);
	document.getElementById("img").src=image_src;
	
	}	

</script> 
<div class="none">
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fbba169f4f4508eb5cc1c5618eeb3c59d' type='text/javascript'%3E%3C/script%3E"));
</script>
</div>
</body>

</html>
